package com.kly.springbootinit.model.enums;

import lombok.Getter;

/**
 * 预约状态枚举类
 * @author YourName
 */
@Getter
public enum ReservationStatusEnum {
    /**
     * 待支付
     */
    PENDING_PAYMENT(0, "待支付"),
    /**
     * 已预约
     */
    RESERVED(1, "已预约"),
    /**
     * 已取消
     */
    CANCELLED(2, "已取消");

    private final Integer code;
    private final String message;

    ReservationStatusEnum(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    /**
     * 根据 code 获取对应的枚举值
     *
     * @param code 状态码
     * @return 对应的枚举
     * @throws IllegalArgumentException 如果找不到对应的枚举值
     */
    public static ReservationStatusEnum valueOfCode(Integer code) {
        return java.util.Arrays.stream(values())
                .filter(e -> e.code.equals(code))
                .findFirst()
                .orElseThrow(() -> new IllegalArgumentException("无效的预约状态码: " + code));
    }
}